package org.example.design.observer.test1;

import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Random;

/**
 * @author huangshen
 * @version 0
 * @description 生成随机数的类
 * @since 2022/2/11 13:58
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class RandomNumberGenerator extends BaseNumberGenerator {

    private Random random = new Random();

    private int number;

    /**
     * 获取数值
     * @return int
     */
    @Override
    public int getNumber() {
        return number;
    }

    /**
     * 生成数值
     */
    @Override
    public void execute() {
        for (int i = 0; i < 5; i++) {
            number = random.nextInt(50);
            notifyObserver();
        }
    }
}
